package br.com.jdobjs.core.proposal;

import java.util.HashSet;
import java.util.Set;

public class ProposalRepository {

	private Set<Proposal> proposals = new HashSet<Proposal>();

	public void addProposal(Proposal proposal) {
		proposals.add(proposal);
	}

	public Set<Proposal> getAllProposals() {
		return proposals;
	}

	public Set<Proposal> getProposalsForOwner(String ownerName) {
		Set<Proposal> result = new HashSet<Proposal>();
		for (Proposal proposal : proposals) {
			for (Owner owner : proposal.getOwners()) {
				if (owner.getName().equals(ownerName)) {
					result.add(proposal);
				}
			}
		}
		return result;
	}

	public Proposal findProposalWithName(String name) {
		for (Proposal proposal : proposals) {
			if (proposal.getName().equals(name)) {
				return proposal;
			}
		}
		return null;
	}
}
